import request from '@/config/axios'

export interface Property {
  propertyId?: number
  propertyName?: string
  valueId?: number
  valueName?: string
}

export interface Sku {
  id?: number
  name?: string
  spuId?: number
  properties?: Property[]
  price?: number
  marketPrice?: number
  costPrice?: number
  barCode?: string
  picUrl?: string
  stock?: number
  weight?: number
  volume?: number
  salesCount?: number
}

export interface Spu {
  id?: number
  name?: string
  categoryId?: number
  keyword?: string
  picUrl?: string
  sliderPicUrls?: string[]
  introduction?: string
  specType?: boolean
  skus?: Sku[]
  description?: string
  sort?: number
  price?: number
  marketPrice?: number
  costPrice?: number
  stock?: number
  createTime?: Date
  status?: number
}

export interface PageParam {
  pageNo?: number
  pageSize?: number
  name?: string
  categoryId?: number
}

export const getSpuPage = (params: PageParam) => {
  return request.get<{ list: Spu[]; total: number }>({ url: '/product/spu/page', params })
}

export const getSpu = (id: number) => {
  return request.get<Spu>({ url: `/product/spu/get-detail?id=${id}` })
}

export const getSpuDetailList = (ids: number[]) => {
  return request.get<Spu[]>({ url: `/product/spu/list?spuIds=${ids}` })
}